﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class dengluaspx : System.Web.UI.Page
{
    private static string sqlconn = System.Configuration.ConfigurationManager.AppSettings["sqlcon"].ToString().Trim();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToLongTimeString();
    }
    protected void btnlogin_Click(object sender, EventArgs e)
    {
        users us = new users();
        string name = txtID.Text.Trim();
        string ps = txtPASSWORD.Text.Trim();
        us.name = name;
        us.ps = ps;
        SqlConnection conn = new SqlConnection(sqlconn);
        try
        {
            conn.Open();
            if (DropDownList1.SelectedIndex == 0)
            {
                //选择客户
                string sq1 = "select count(*) from H_TABLE where H_NAME='" + name + "'";
                SqlCommand codd = new SqlCommand(sq1, conn);
                int ma = (int)codd.ExecuteScalar();
                if (ma > 0)
                {
                    int rd = us.denlu(us);


                    if (rd == 0)
                    {

                        Response.Write("<script>window.alert(\"账号密码错误，请重新输入！\")</script>");

                    }
                    else
                    {
                        Session["name"] = name;
                        Response.Redirect("~/temaiyao.aspx");
                    }



                }
                else
                {
                    Response.Write("<script>window.alert(\"用户不存在！\")</script>");
                }


            }
            else if (DropDownList1.SelectedIndex == 1)
            {
                //选择管理员
                string sql = "select count(*) T_ID from T_TABLE where T_NAME='" + name + "'and T_PW='" + ps + "'";
                SqlCommand comm = new SqlCommand(sql, conn);
                int result = (int)comm.ExecuteScalar();
                if (result > 0)
                {


                    Session["name"] = name;
                    Response.Redirect("~/zhuye.aspx");
                }
                else
                {
                    Response.Write("<script>window.alert(\"用户不存在！\")</script>");
                }
            }


        }
        catch (SqlException ex)
        { throw new Exception(ex.Message); }
        finally
        {
            conn.Close();
        }
    }
}